# Name: [Blog Comment Test]
# By: [Wyatt Preul]
# This will test creating a new snippet
# Maintenance:
#   [10/05/2006] : [WLP] : Created
#

require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'

#_replace_Template_with_the_short_name_of_your_test_case
class TC_BlogDescriptionManagement_test < Test::Unit::TestCase
    
    def startup
      $Title = randomChar(7)
      $Description = randomChar(30)
      $News = randomChar(25)
      $MetaDescription = randomChar(10)
      $MetaKeywords = randomChar(10)
      @@ie = Watir::IE.start($SITE_URL)
    end
    
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))		
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))
      assert(ie.link(:text, /Administration/).exists?)
      ie.link(:text, /Administration/).click
      assert(ie.contains_text(/Community Server Announcements/))
    end
    
    def test_07_verifyControlPanelTabBarLinks
      assert_equal $SITE_URL + 'controlpanel/default.aspx', ie.link(:text, 'Dashboard').href
      assert_equal $SITE_URL + 'controlpanel/blogs', ie.link(:text, 'My Blogs').href
      assert_equal $SITE_URL + 'controlpanel/photos/', ie.link(:text, 'My Photos').href
      assert_equal $SITE_URL + 'controlpanel/files', ie.link(:text, 'My Files').href
      assert_equal $SITE_URL + 'controlpanel/moderation', ie.link(:text, 'Forums Moderation').href
      assert_equal $SITE_URL + 'controlpanel/Setup.aspx', ie.link(:text, 'Administration').href
      assert_equal $SITE_URL + 'controlpanel/Reporting/default.aspx', ie.link(:text, 'Reporting').href
    end
    
    def test_08_navigateToSnippetManagement
      ie.goto($SITE_URL + 'ControlPanel/Blogs/DescOptions.aspx')
      
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
    end
    
    def test_09_populateFieldsAndSave
      #assert(ie.text_field(:id, /TaskRegion_Title$/).exists?)
      #ie.text_field(:id, /TaskRegion_Title$/).value = $Title
      #assert(ie.text_field(:id, /TaskRegion_Title$/).verify_contains($Title))
      assert(ie.text_field(:id, /Name$/).exists?)
      ie.text_field(:id, /Name$/).value = $Title
      assert(ie.text_field(:id, /Name$/).verify_contains($Title))
      
      #assert(ie.text_field(:id, /TaskRegion_Description$/).exists?)
      #ie.text_field(:id, /TaskRegion_Description$/).value = $Description
      #assert(ie.text_field(:id, /TaskRegion_Description$/).verify_contains($Description))
      assert(ie.text_field(:id, /Description$/).exists?)
      ie.text_field(:id, /Description$/).value = $Description
      assert(ie.text_field(:id, /Description$/).verify_contains($Description))
      
      assert(ie.text_field(:id, /News$/).exists?)
      ie.text_field(:id, /News$/).value = $News
      assert(ie.text_field(:id, /News$/).verify_contains($News))
      
      assert(ie.text_field(:id, /MetaTagDescription$/).exists?)
      ie.text_field(:id, /MetaTagDescription$/).value = $MetaDescription
      assert(ie.text_field(:id, /MetaTagDescription$/).verify_contains($MetaDescription))
      
      assert(ie.text_field(:id, /MetaTagKeywords$/).exists?)
      ie.text_field(:id, /MetaTagKeywords$/).value = $MetaKeywords
      assert(ie.text_field(:id, /MetaTagKeywords$/).verify_contains($MetaKeywords))
      
      assert(ie.link(:id, /SaveButton$/).exists?)
      ie.link(:id, /SaveButton$/).click
    end

    def test_10_checkSaveResults
      assert(ie.contains_text('Your options have been successfully saved'))
      assert(ie.text_field(:id, /Name$/).verify_contains($Title))
      assert(ie.text_field(:id, /Description$/).verify_contains($Description))
      assert(ie.text_field(:id, /News$/).verify_contains($News))
      assert(ie.text_field(:id, /MetaTagDescription$/).verify_contains($MetaDescription))
      assert(ie.text_field(:id, /MetaTagKeywords$/).verify_contains($MetaKeywords))
    end
    
    def test_99_closeIE
      ie.close
    end
end